﻿<UserControl x:Class="ScrumFactory.Risks.RisksList"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:SF="clr-namespace:ScrumFactory;assembly=ScrumFactory"
             xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"
             xmlns:SF_Converters="clr-namespace:ScrumFactory.Windows.Helpers.Converters;assembly=ScrumFactory.Windows.Helpers"
             xmlns:SF_Comp="clr-namespace:ScrumFactory.Composition;assembly=ScrumFactory.Composition" 
             
             xmlns:KExt="clr-namespace:System.Windows.KExtensions;assembly=System.Windows.KExtensions"
             
             xmlns:props="clr-namespace:ScrumFactory.Risks.Properties"
             mc:Ignorable="d" 
             
             x:Name="thisView"
             
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.InputBindings>
        <KeyBinding Key="Enter" Command="{Binding AddRiskCommand}"/>
    </UserControl.InputBindings>

    <SF_Helpers:PanelLayout Title="{Binding PanelName}"                            
                            SF_Comp:CommandBehavior.RoutedEventName="Loaded"
                            SF_Comp:CommandBehavior.TheCommandToRun="{Binding OnLoadCommand}">
        
        <SF_Helpers:PanelLayout.Toolbar>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
                <ToolBar Grid.Row="0">



                    <MenuItem
                        Header="{x:Static props:Resources.Add_risk}" Focusable="False"
                        IsEnabled="{Binding UserCanEdit}">
                        <MenuItem.Icon>
                            <Image Source="/Images/ToolBar/Add.png" Width="32" Height="32" Stretch="Uniform"/>
                        </MenuItem.Icon>
                        <MenuItem.Style>
                            <Style BasedOn="{StaticResource Toolbar_MenuItemStyleHideWhenDisabled}" TargetType="MenuItem">
                                <Style.Triggers>
                                    <Trigger Property="MenuItem.IsPressed" Value="True">
                                        <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=addTextBox}"/>
                                    </Trigger>

                                </Style.Triggers>
                            </Style>
                        </MenuItem.Style>
                    </MenuItem>

                    <MenuItem                                
                    Header="{x:Static props:Resources.Show_mitigated}" Focusable="False"
                    IsCheckable="True"
                    IsChecked="{Binding ShowMitigatedRisks}">
                        <MenuItem.Icon>
                            <Image Source="/Images/RiskIndicators/GreenSquare.png" Width="32" Height="32" Stretch="Uniform"/>
                        </MenuItem.Icon>
                    </MenuItem>
                </ToolBar>

                <Grid x:Name="newItemPanel" 
                            Grid.Row="1"  
                            Style="{StaticResource NewItemPanelAutoClose}">
                    <DockPanel VerticalAlignment="Top" HorizontalAlignment="Stretch">
                        <TextBlock Style="{StaticResource LabelTextBlock}" Text="{x:Static props:Resources.Risk}" VerticalAlignment="Center" DockPanel.Dock="Left"/>
                        <TextBox   
                                KExt:SpellCheck.IsEnabled="True"
                                x:Name="addTextBox" BorderBrush="{StaticResource TextBoxBackgroundBrush}"
                                ToolTip="{x:Static props:Resources.Risk}"  DockPanel.Dock="Right"
                                Text="{Binding NewRiskDescription, UpdateSourceTrigger=PropertyChanged}"                                                         
                                HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
                    </DockPanel>

                </Grid>
                

            </Grid>
        </SF_Helpers:PanelLayout.Toolbar>

        <SF_Helpers:PanelLayout.Content>
            <Grid>
                <ListView
                HorizontalAlignment="Stretch"                           
                    Style="{StaticResource ListViewNoHeader}"
                ScrollViewer.VerticalScrollBarVisibility="Auto"                                                        
                SF_Helpers:ListViewColumnsExtension.Stretch="True"
                    
                SF_Helpers:ItemActivation.ActivationMode="Both"            
                SF_Helpers:ItemActivation.TheCommandToRun="{Binding ShowDetailCommand}"                                    

                    
                Padding="10,0,40,0"
                ItemsSource="{Binding FilteredRisks}">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="{x:Static props:Resources.Impact}" Width="100">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Vertical">
                                            <ComboBox         
                                            IsTabStop="False"
                                            IsEnabled="{Binding Model.UserCanEdit, ElementName=thisView}"
                                            Style="{StaticResource CleanComboBox}"                                                                                
                                            SelectedValue="{Binding Risk.Impact, Converter={StaticResource EnumToShortConverter}, ConverterParameter={x:Type SF:RiskImpacts},UpdateSourceTrigger=PropertyChanged}"                                                                                      
                                            SF_Comp:CommandBehavior.RoutedEventName="SelectionChanged"
                                            SF_Comp:CommandBehavior.TheCommandToRun="{Binding ChangeRiskImpactCommand}"
                                            ItemsSource="{Binding Source={StaticResource RiskImpactList}}">
                                                <ComboBox.ItemTemplate>
                                                    <DataTemplate>
                                                        <StackPanel Orientation="Vertical">
                                                            <Image DataContext="{Binding}" Style="{StaticResource RiskIndicatorImage}" HorizontalAlignment="Center" />
                                                            <TextBlock Text="{Binding ., Converter={StaticResource LocalizeConverter}}" HorizontalAlignment="Center" FontSize="{StaticResource SmallFontSize}"/>
                                                        </StackPanel>
                                                    </DataTemplate>
                                                </ComboBox.ItemTemplate>
                                            </ComboBox>
                                            <TextBlock Text="{x:Static props:Resources.Impact}" FontSize="{StaticResource SmallFontSize}" HorizontalAlignment="Center"/>
                                        </StackPanel>
                                        
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="{x:Static props:Resources.Probability}" Width="100">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Vertical">
                                            <ComboBox         
                                            IsTabStop="False"
                                            IsEnabled="{Binding Model.UserCanEdit, ElementName=thisView}"
                                            Style="{StaticResource CleanComboBox}"                                                                                
                                            SelectedValue="{Binding Risk.Probability, Converter={StaticResource EnumToShortConverter}, ConverterParameter={x:Type SF:RiskProbabilities},UpdateSourceTrigger=PropertyChanged}"                                                                                      
                                            SF_Comp:CommandBehavior.RoutedEventName="SelectionChanged"
                                            SF_Comp:CommandBehavior.TheCommandToRun="{Binding ChangeRiskProbabilityCommand}"
                                            ItemsSource="{Binding Source={StaticResource RiskProbabilityList}}">
                                                <ComboBox.ItemTemplate>
                                                    <DataTemplate>
                                                        <StackPanel Orientation="Vertical">
                                                            <Image DataContext="{Binding}" Style="{StaticResource RiskIndicatorImage}" HorizontalAlignment="Center" />
                                                            <TextBlock 
                                                        Text="{Binding ., Converter={StaticResource LocalizeConverter}}"
                                                        HorizontalAlignment="Center" TextWrapping="Wrap"
                                                        FontSize="{StaticResource SmallFontSize}"/>
                                                        </StackPanel>
                                                    </DataTemplate>
                                                </ComboBox.ItemTemplate>
                                            </ComboBox>
                                            <TextBlock Text="{x:Static props:Resources.Probability}" FontSize="{StaticResource SmallFontSize}" HorizontalAlignment="Center"/>
                                        </StackPanel>
                                        
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="{x:Static props:Resources.Risk}">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Vertical">
                                            <TextBlock HorizontalAlignment="Stretch">                                                
                                                <Hyperlink                                                     
                                                    Command="{Binding Model.ShowDetailCommand, ElementName=thisView}"
                                                    CommandParameter="{Binding .}">
                                                    <Run FontSize="{StaticResource BigFontSize}" Text="{Binding Risk.RiskDescription}" />    
                                                </Hyperlink>                                                
                                                <Image Source="/Images/Toolbar/Closed_locker.png" Width="16" Height="16" Stretch="Uniform">
                                                    <Image.Style>
                                                        <Style>
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding Risk.IsPrivate}" Value="False">
                                                                    <Setter Property="Image.Visibility" Value="Collapsed"/>
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </Image.Style>
                                                </Image>
                                            </TextBlock>                                            
                                            <TextBlock Text="{Binding Risk.RiskAction}" Margin="0,5,0,0"/>
                                            <TextBlock Text="{Binding Risk.UpdatedAt, StringFormat={x:Static props:Resources.updated_at_N}}" FontStyle="Italic" FontSize="{StaticResource SmallFontSize}"/>
                                        </StackPanel>                                        
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>                            
                            
                        </GridView>
                    </ListView.View>
                </ListView>
                <ContentControl
                    Style="{StaticResource LoadingAnimationContent}"/>
            </Grid>
            
        </SF_Helpers:PanelLayout.Content>

    </SF_Helpers:PanelLayout>
</UserControl>
